#!/usr/bin/env python
# encoding: utf-8
'''
@author: liuchong
@contact: lucas@007vin.com
@software: garner
@file: banzhou.py
@time: 2020/9/9 2:44 下午
@desc:
'''

import re
import pandas as pd
from models.audi.cars_audi import CarsAudi
from models.basemodel import database
audi = CarsAudi.select()
for a in audi:
    trans_add = []
    trans_desc = a.trans_desc
    trans_info = trans_desc.split(',')
    for i in trans_info:
        if i == 'CVT无级变速':
            trans_add.append('CVT无级变速(模拟6挡)')
            trans_add.append('CVT无级变速(模拟7挡)')
            trans_add.append('CVT无级变速(模拟8挡)')
        else:
            trans_add.append(i)
    trans_add = ','.join(trans_add)
    print(trans_add)
    a.trans_desc = trans_add
    a.save()
database.commit()

exit(0)
def change_name(driver):
    if driver == '前置前驱':
        return '两驱'
    elif driver == '全轮驱动':
        return '四驱'

file = '/Users/liuchong/Downloads/cars_audi_All.csv'
df = pd.read_csv(file)
df['brandCode']='audi'
df['drive_new']=df['drive'].apply(change_name)
# for index, row in df.iterrows():
#     drive_info = []
#     trans_desc = row.to_dict()['transmission']
#     result = re.sub('\(.*?\)|（.*?\）', '', trans_desc)
#     row.to_dict()['trans_desc'] = result
#     row.to_dict()['brandCode'] = 'audi'
#     drive = row.to_dict()['drive']
#     drive = drive.split(',')
#     for i in drive:
#         if i == '前置前驱':
#             drive_info.append('两驱')
#         if i == '全轮驱动':
#             drive_info.append('四驱')
#     drive_new = ','.join(drive_info)
#     row.to_dict()['drive_new'] = drive_new
print(df.head(10))
df.to_csv('123.csv')




